package com.jiuli.liping.example;

import com.jiuli.liping.mypackage.ArrayOfString;
import com.jiuli.liping.mypackage.WorkflowServiceXmlLocator;
import com.jiuli.liping.mypackage.WorkflowServiceXmlPortType;
import com.jiuli.liping.util.XmlUtil;
import com.jiuli.liping.vo.*;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

public class HelloWorldClient {
  public static void main(String[] argv) {
    //WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();// 工作流程请求信息

    //ReturnMessage rm = new ReturnMessage();
    //Gson gson = new Gson();
    //ImportTrade it = gson.fromJson(importTrade, ImportTrade.class);

    WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();// 工作流程请求信息

    int userid = 1226;// 用户ID
    workflowRequestInfo.setCanView(true);// 显示
    workflowRequestInfo.setCanEdit(true);// 可编辑
    workflowRequestInfo.setRequestName("商城物品领用审批");// 请求标题
    workflowRequestInfo.setRequestLevel("0");// 请求重要级别 0：正常 1：重要 2：紧急
    workflowRequestInfo.setCreatorId(userid + "");// 创建者ID 创建流程时为必输项

    WorkflowBaseInfo workflowBaseInfo = new WorkflowBaseInfo();// 工作流信息
    workflowBaseInfo.setWorkflowId("570");// 流程ID
    workflowBaseInfo.setWorkflowName("商城物品领用审批");// 流程名称
    workflowBaseInfo.setWorkflowTypeName("商城物品领用审批");// 流程类型名称
    workflowRequestInfo.setWorkflowBaseInfo(workflowBaseInfo);

    WorkflowMainTableInfo workflowMainTableInfo = new WorkflowMainTableInfo();// 主表
    WorkflowRequestTableRecord[] workflowRequestTableRecord = new WorkflowRequestTableRecord[1];
    WorkflowRequestTableField[] workflowRequestTableField = new WorkflowRequestTableField[2];
    workflowRequestTableField[0] = new WorkflowRequestTableField();
    workflowRequestTableField[0].setFieldName("gonghao");
    workflowRequestTableField[0].setFieldValue("6762");
    workflowRequestTableField[0].setView(true);
    workflowRequestTableField[0].setEdit(true);

    workflowRequestTableField[1] = new WorkflowRequestTableField();
    workflowRequestTableField[1].setFieldName("beizhu");
    workflowRequestTableField[1].setFieldValue("asdsdasd");
    workflowRequestTableField[1].setView(true);
    workflowRequestTableField[1].setEdit(true);

    workflowRequestTableRecord[0] = new WorkflowRequestTableRecord();
    workflowRequestTableRecord[0].setWorkflowRequestTableFields(workflowRequestTableField);
    workflowMainTableInfo.setRequestRecords(workflowRequestTableRecord);

    workflowRequestInfo.setWorkflowMainTableInfo(workflowMainTableInfo);

    //List<ImportTradeDetail> list = new ArrayList<ImportTradeDetail>();
    //list = it.getDetails();
    WorkflowDetailTableInfo[] workflowDetailTableInfo = new WorkflowDetailTableInfo[1];
    WorkflowRequestTableRecord[] workflowRequestTableRecordDetail = new WorkflowRequestTableRecord[1];
    for (int i = 0; i < 1; i++) {
      WorkflowRequestTableField[] workflowRequestTableFieldDetail = new WorkflowRequestTableField[3];
      workflowRequestTableFieldDetail[0] = new WorkflowRequestTableField();
      workflowRequestTableFieldDetail[0].setFieldName("lpmc");
      workflowRequestTableFieldDetail[0].setFieldValue("sdas");
      workflowRequestTableFieldDetail[0].setView(true);
      workflowRequestTableFieldDetail[0].setEdit(true);

      workflowRequestTableFieldDetail[1] = new WorkflowRequestTableField();
      workflowRequestTableFieldDetail[1].setFieldName("sl");
      workflowRequestTableFieldDetail[1].setFieldValue("12");
      workflowRequestTableFieldDetail[1].setView(true);
      workflowRequestTableFieldDetail[1].setEdit(true);

      workflowRequestTableFieldDetail[2] = new WorkflowRequestTableField();
      workflowRequestTableFieldDetail[2].setFieldName("dj");
      workflowRequestTableFieldDetail[2].setFieldValue("6");
      workflowRequestTableFieldDetail[2].setView(true);
      workflowRequestTableFieldDetail[2].setEdit(true);

      workflowRequestTableRecordDetail[i] = new WorkflowRequestTableRecord();

      workflowRequestTableRecordDetail[i].setWorkflowRequestTableFields(workflowRequestTableFieldDetail);
    }
    workflowDetailTableInfo[0] = new WorkflowDetailTableInfo();
    workflowDetailTableInfo[0].setWorkflowRequestTableRecords(workflowRequestTableRecordDetail);

    workflowRequestInfo.setWorkflowDetailTableInfos(workflowDetailTableInfo);

    String requestInfo = "";
    XmlUtil xmlu = XmlUtil.getInstance();
    try {
      requestInfo = xmlu.objToXml(workflowRequestInfo);
    } catch (Exception e) {
      e.printStackTrace();
    }

    String url = "http://oa.jiuli.com:99/services/WorkflowServiceXml?wsdl";
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(url);
    QName name = new QName("webservices.services.weaver.com.cn", "doCreateWorkflowRequest");
    Object[] objects;
    try {
      objects = client.invoke(name, requestInfo, userid);
      System.out.println(objects[0]);
      System.out.println(objects.length);
    } catch (Exception e) {

      e.printStackTrace();
    }
//  if ("0".equals(it.getFlag())) {
//   importedMaterialsService.updateInReview(it.getId());
//  }
//  if ("1".equals(it.getFlag())) {
//   importedMaterialsService.updateSteelInReview(it.getId());
//  }
    //rm.setSuccess(true);
  }
}
